//
//  MySelfViewController.m
//  EDPS
//
//  Created by 张维扬 on 15/11/23.
//  Copyright © 2015年 张维扬. All rights reserved.
//

#import "MySelfViewController.h"
#import "MessageTotalViewController.h"
#import "MusicViewController.h"
#import "WeatherViewController.h"
#import "ErCodeViewController.h"
#import "LocationViewController.h"

@interface MySelfViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,retain) UITableView *tableView;
@property (nonatomic,retain) UIImageView *imageView;
@property (nonatomic,retain) NSMutableArray *dataArr;

@end

@implementation MySelfViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"我的";
    self.navigationController.navigationBar.barTintColor = RGBA(62, 176, 193, 1);
    [self setAutomaticallyAdjustsScrollViewInsets:NO];
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle =  UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    self.tableView.contentInset = UIEdgeInsetsMake(200.0+64, 0, 0, 0);
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -200.0, self.view.frame.size.width, 200)];
    self.imageView.image = [UIImage imageNamed:@"b7003af33a87e950d89ca96e12385343fbf2b42d.jpg"];
    self.imageView.contentMode = UIViewContentModeScaleAspectFill;
    [self.tableView addSubview:self.imageView];
    self.dataArr = [NSMutableArray arrayWithObjects:@"",@"我的游记",@"边走边听",@"天气情况",@"扫一扫",@"退出程序", nil];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"deq"];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"deq"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = [self.dataArr objectAtIndex:indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 1)
    {
        MessageTotalViewController *message = [[MessageTotalViewController alloc] init];
        message.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:message animated:YES];
    }
    if (indexPath.row == 2)
    {
        MusicViewController *music = [[MusicViewController alloc] init];
        music.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:music animated:YES];
    }
    if (indexPath.row == 3)
    {
        WeatherViewController *weather = [[WeatherViewController alloc] init];
        weather.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:weather animated:YES];
    }
    if (indexPath.row == 4)
    {
        ErCodeViewController *erCode = [[ErCodeViewController alloc] init];
        erCode.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:erCode animated:YES];
    }
    if (indexPath.row == 5)
    {
        [UIView animateWithDuration:1 animations:^{
        } completion:^(BOOL finished) {
            exit(0);
        }];
    }
    
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat y = scrollView.contentOffset.y + 64 ;
    if (y < -200)
    {
        CGRect frame = self.imageView.frame;
        frame.origin.y = y;
        frame.size.height =  -y;
        self.imageView.frame = frame;
    }
}
@end